//
//  TopView.m
//  Park
//
//  Created by 123456 on 2017/10/27.
//  Copyright © 2017年 YTYangK. All rights reserved.
//

#import "TopView.h"
#import "DriverOrderViewController.h"
#import "ReservationCarViewController.h"
#import "MiddleMenuCollectionViewCell.h"
#import "billViewController.h"
#import "companyViewController.h"
#import "RestaurantViewController.h"
#import "AllOrdersInTheRestaurantViewController.h"
#import "ReservationViewController.h"

@implementation TopView
{
    UITabBarController *tabBarVc;
    UINavigationController *nav;
    
}





- (void)awakeFromNib {
    [super awakeFromNib];

    tabBarVc = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    nav = (UINavigationController *)tabBarVc.selectedViewController;
    
     if (SYSTEM_VERSION_EQUAL_TO_W_orH(SCREEN_HEIGHT, @"667.0")){
        
         self.AdvertisementH.constant = 140;
         
    }else if (SYSTEM_VERSION_EQUAL_TO_W_orH(SCREEN_HEIGHT, @"736.0")){

        self.AdvertisementH.constant = 145;
        
    }else if (SYSTEM_VERSION_EQUAL_TO_W_orH(SCREEN_HEIGHT, @"812.0")){
        
        self.AdvertisementH.constant = 145;
    }
    
    self.TitleArr = @[@"餐厅",@"专车",@"宿舍",@"订单"];
    
    [self.TitleCollectionview registerNib:[UINib nibWithNibName:@"MiddleMenuCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"cell"];

    
    
    //图像添加点击事件（手势方法）
    self.AdvertisementImage.userInteractionEnabled = YES;
    UITapGestureRecognizer * PrivateLetterTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAvatarView)];
    PrivateLetterTap.numberOfTouchesRequired = 1; //手指数
    PrivateLetterTap.numberOfTapsRequired = 1; //tap次数
    PrivateLetterTap.delegate= self;
    self.AdvertisementImage.contentMode = UIViewContentModeScaleToFill;
    [self.AdvertisementImage addGestureRecognizer:PrivateLetterTap];
    
    
    

}






//collectionview代理方法
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    MiddleMenuCollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
  
    cell.TitleImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"01-%ld",indexPath.row+1]];
    cell.Titlelabel.text = [NSString stringWithFormat:@"%@",self.TitleArr[indexPath.row]];
    
    
    return cell;
    
}



//collectionview的显示
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.TitleArr.count;
}

//大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return CGSizeMake(self.TitleCollectionview.size.width/4, self.TitleCollectionview.size.height);
}


//选中状态
-( void )collectionView:( UICollectionView *)collectionView didSelectItemAtIndexPath:( NSIndexPath *)indexPath{

    if (indexPath.row == 0) {
        RestaurantViewController *r = [[RestaurantViewController alloc]init];
        [nav pushViewController:r animated:YES];
        

    }else if (indexPath.row == 1){
        
        
        ReservationCarViewController *r = [[ReservationCarViewController alloc]init];
        [nav pushViewController:r animated:YES];

        
    }else if (indexPath.row == 2){
        

        ReservationViewController *r = [[ReservationViewController alloc]init];
        [nav pushViewController:r animated:YES];

        
    }else if (indexPath.row == 3){
        
        billViewController *b = [[billViewController alloc]init];
        [nav pushViewController:b animated:YES];



    }else if (indexPath.row == 4){
        

        
    }else if (indexPath.row == 5){

        
    }else if (indexPath.row == 6){

        
    }else if (indexPath.row == 7){

        
    }else if (indexPath.row == 8){

        
    }



    
}

-(void)tapAvatarView{
    
    RestaurantViewController *r = [[RestaurantViewController alloc]init];
    [nav pushViewController:r animated:YES];
    

    
}







@end
